package ox;

import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Ox {
    public static void main(String[] args) {
        compare();
    }

    public static void compare() {
        int a=0;
        int b=0;
        for (int x=0;x<5;x++){
            if (a==4){
                break;
            }else {
                int[] newNumber = consumer();
                int[] newRed = ranDom();
                for (int i=0;i<newNumber.length;i++){
                    for (int j=0;j<newRed.length;j++){
                        if (newNumber[i]==newRed[j]){
                            b++;
                        }
                        if (newNumber[i]==newRed[j]&&i==j){
                            a++;
                        }
                    }
                }
                System.out.println(a+"A"+"和"+b+"B");
                System.out.println("你还有"+(4-x)+"机会");
            }
        }
    }

    public static int[] consumer() {
        int[] number = new int[5];
        for (int i = 0; i < number.length; i++) {
            while (true) {
                Scanner scan = new Scanner(System.in);
                System.out.println("输入第" + (i + 1) + "个数");
                try {
                    int receive = scan.nextInt();
                    if (receive < 10) {
                        number[i] = receive;
                        break;
                    }
                } catch (InputMismatchException e) {
                    System.out.println("只能数数字");
                }
            }
            for (int j = 0; j < i; j++) {
                if (number[i] == number[j]) {
                    i--;
                    break;
                }
            }
        }
        System.out.println("输入号码：" + Arrays.toString(number));
        return number;
    }

    public static int[] ranDom() {
        int[] red = new int[5];
        for (int i = 0; i < red.length; i++) {
            red[i] = (int) (Math.random() * 10 + 0);
            for (int j = 0; j < i; j++) {
                if (red[i] == red[j]) {
                    i--;
                    break;
                }
            }
        }
        System.out.println("随机号码：" + Arrays.toString(red));
        return red;
    }
}
